package ucm;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import model.Database_Model;

public class UCUpdateSearch {

    private String[] airinformation;
    private String search;

    public UCUpdateSearch() {
    }

    public UCUpdateSearch(String search) {
        this.search = search;
    }

    public String[] run() {
        try {
            Connection con = new Database_Model().getConnection();
            Statement stmt = con.createStatement();
            ResultSet res = stmt.executeQuery("select * from airline where Destination='" + search + "'");
            if (res.first() && !res.wasNull()) {
                res.last();
                airinformation = new String[res.getRow()];
                res.beforeFirst();
                int count = 0;
                while (res.next()) {
                    airinformation[count] = res.getString("Airline") + ";" + res.getString("Price") + ";" +
                            res.getString("Destination") + ";" + res.getString("Time") + ";" + res.getString("GST");
                    System.out.println(airinformation[count]);
                    count++;
                }
            } else {
                airinformation = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            airinformation = null;
        }
        return airinformation;
    }
}
